#ifndef _BIT_MAP_H_
#define _BIT_MAP_H_

#include <stdint.h>

#define SET_SIZE    1024
#define PER_NBITS   32

typedef struct {
    uint32_t bits[SET_SIZE/PER_NBITS]; // 1024 / 32
} bitset;

#define BIT_ELT(d)      ((d) / PER_NBITS)
#define BIT_MASK(d)     ((uint32_t)1 << ((d) % PER_NBITS))

/* We don't use `memset' because this would require a prototype and
   the array isn't too big.  */
#define BIT_ZERO(set) \
  do {                                                                        \
    unsigned int __i;                                                         \
    for (__i = 0; __i < SET_SIZE / PER_NBITS; ++__i)                          \
      (set)->bits[__i] = 0;                                                   \
  } while (0)

#define BIT_SET(d, set) \
    ((set)->bits[BIT_ELT(d)] |= BIT_MASK(d))

#define BIT_CLR(d, set) \
    ((set)->bits[BIT_ELT(d)] &= ~BIT_MASK(d))

#define BIT_ISSET(d, set) \
    (((set)->bits[BIT_ELT(d)] & BIT_MASK(d)) != 0)

#endif /* _BIT_MAP_H_ */
